package hapi.geom;

import hapi.math.Vector2D;

class LineSegment implements Container<Vector2D> {
	
	public var b:Vector2D;
	public var e:Vector2D;
	
	public function new(from, to){
		b = from;
		e = to;
	}
	
	public inline function contains(p:Vector2D){
		if( Math.min(b.x, e.x) > p.x || Math.max(b.x, e.x) < p.x 
		|| Math.min(b.y, e.y) > p.y || Math.max(b.y, e.y) < p.y){
			return false;
		}else{
			var v = p.minusNew(b);
			var dir = e.minusNew(b);
			return v.x/v.y == dir.x/dir.y;
		}
	}
	
	public function clone() {
		return new LineSegment(b.clone(), e.clone());
	}
	
	public function toString(){
		return "LineSegment("+b+","+e+")";
	}
}